package com.laycoding.rocketmq.producer.controller;

import com.laycoding.rocketmq.producer.entity.RocketMqMessage;
import com.laycoding.rocketmq.producer.service.RocketMqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * created with IntelliJ IDEA.
 *
 * @author: guidada
 * @date: 2021/04/09/11:12
 * @description:
 */
@RestController
@RequestMapping("/message")
public class TestController {


    @Autowired
    private RocketMqService rocketMqService;

    /*
     *
     * @author guidada
     * @date 2021/4/9 0009
     * @param msg
     * @return java.lang.String
     * @description ~
     */
    @RequestMapping("/send/{msg}")
    public String send(@PathVariable String msg) {
        RocketMqMessage rocketMqMessage = new RocketMqMessage();

        rocketMqMessage.setTopic("test-top-1");
        rocketMqMessage.setTags("registered");
        rocketMqMessage.setContent(msg);

        rocketMqService.send(rocketMqMessage);

        return "ok";
    }

    /*
     *
     * @author guidada
     * @date 2021/4/9 0009
     * @param
     * @return java.lang.String
     * @description ~
     */
    @RequestMapping("/motify")
    public String sendSync() {
        RocketMqMessage rocketMqMessage = new RocketMqMessage();

        rocketMqMessage.setTopic("test-top-1");
        rocketMqMessage.setTags("modify");
        rocketMqMessage.setContent("注册操作");

        rocketMqService.asyncSend(rocketMqMessage);
        return "ok";
    }

}
